package com.nginxmanager.server.serverIpm;

import com.nginxmanager.server.NginxAdmin;
import org.springframework.stereotype.Service;

import java.io.IOException;

/**
 * Created by Administrator on 2018-01-02.
 */
@Service
public class NginxAdminIpm implements NginxAdmin {
    Runtime runtime = Runtime.getRuntime();
    @Override
    public void point(String str) {

    }

    @Override
    public String startWind(String str) {
        String cd[]=str.split(":");
        try {
//            Process process = runtime.exec("cmd.exe /c D: && cd D:\\nginx && start nginx.exe");
            Process process = runtime.exec("cmd.exe /c "+cd[0]+": && cd "+str+" && start nginx.exe");
        } catch (IOException e) {
            e.printStackTrace();
            return "Nginx启动失败，检查端口占用或者检查文件路径是否出错！";
        }
        return "Nginx启动成功";
    }

    @Override
    public String stopWind(String str) {
        String cd[]=str.split(":");
        try {
            Process process = runtime.exec("cmd.exe /c "+cd[0]+": && cd "+str+" && nginx -s quit");
        } catch (IOException e) {
            e.printStackTrace();
            return "Nginx关闭出错";
        }
        return "Nginx关闭成功";
    }
}
